package com.juzhi.dvrapp.widget;

import android.app.Dialog;
import android.content.Context;
import android.view.Gravity;
import android.widget.TextView;

import com.juzhi.dvrapp.R;


/**
 * 加载activity时的dialog
 */
public class LoadingActivityDialog extends Dialog {

	private static Context context = null;

	private static LoadingActivityDialog customProgressDialog = null;
	private static TextView textView;

	public static synchronized LoadingActivityDialog getInstance(Context context) {
		if (customProgressDialog == null) {
			synchronized (LoadingActivityDialog.class) {
				if (customProgressDialog == null) {
					customProgressDialog = new LoadingActivityDialog(context, R.style.CustomProgressDialog);
				}
			}
		}
		return customProgressDialog;
	}

	public LoadingActivityDialog(Context context) {

		super(context);

		this.context = context;

	}

	public LoadingActivityDialog(Context context, int theme) {

		super(context, theme);
		this.context = context;

	}

	public static LoadingActivityDialog createNetErrorDialog(Context context, String str){
		customProgressDialog = new LoadingActivityDialog(context,R.style.CustomProgressDialog);

		customProgressDialog.setContentView(R.layout.dialog_error);

		TextView textView = (TextView) customProgressDialog.findViewById(R.id.dialog_error_text);
		textView.setText(str);

		customProgressDialog.getWindow().getAttributes().gravity = Gravity.CENTER;

		customProgressDialog.setCanceledOnTouchOutside(true);
//
		customProgressDialog.setCancelable(true);//返回键

		return customProgressDialog;
	}

	public static LoadingActivityDialog createDialog(Context context) {

		customProgressDialog = new LoadingActivityDialog(context,R.style.CustomProgressDialog);

		customProgressDialog.setContentView(R.layout.dialog_loadding);

		customProgressDialog.getWindow().getAttributes().gravity = Gravity.CENTER;

		customProgressDialog.setCanceledOnTouchOutside(false);
//
//		customProgressDialog.setCancelable(false);//返回键

		return customProgressDialog;

	}

	public static LoadingActivityDialog createDialog(Context context, int str) {

		customProgressDialog = new LoadingActivityDialog(context,R.style.CustomProgressDialog);

		customProgressDialog.setContentView(R.layout.dialog_loadding);

		textView = (TextView) customProgressDialog.findViewById(R.id.dialog_text);
		textView.setText(context.getString(str));

		ProgressWheel ProgressWheel = (ProgressWheel) customProgressDialog.findViewById(R.id.dialog_ProgressWheel);

		customProgressDialog.getWindow().getAttributes().gravity = Gravity.CENTER;

		customProgressDialog.setCanceledOnTouchOutside(true);
//
		customProgressDialog.setCancelable(true);//返回键

		return customProgressDialog;

	}

	public static LoadingActivityDialog createDialog(Context context, int str,int Visibility) {

		customProgressDialog = new LoadingActivityDialog(context,R.style.CustomProgressDialog);

		customProgressDialog.setContentView(R.layout.dialog_loadding);

		textView =  (TextView) customProgressDialog.findViewById(R.id.dialog_text);
		textView.setText(context.getString(str));

		ProgressWheel ProgressWheel = (ProgressWheel) customProgressDialog.findViewById(R.id.dialog_ProgressWheel);
		ProgressWheel.setVisibility(Visibility);

		customProgressDialog.getWindow().getAttributes().gravity = Gravity.CENTER;

		customProgressDialog.setCanceledOnTouchOutside(false);
//
//		customProgressDialog.setCancelable(false);//返回键

		return customProgressDialog;

	}

	/**
	 *  创建提示框
	 * @param context 上下文
	 * @param str  提示文字内容
	 * @param Visibility  是否需要ProgressWheel
	 * @param b 是否可以窗口之外关闭
     * @return
     */
	public static LoadingActivityDialog createDialog(Context context, int str,int Visibility,boolean b) {

		customProgressDialog = new LoadingActivityDialog(context,R.style.CustomProgressDialog);

		customProgressDialog.setContentView(R.layout.dialog_loadding);

		textView = (TextView) customProgressDialog.findViewById(R.id.dialog_text);
		textView.setText(context.getString(str));

		ProgressWheel ProgressWheel = (ProgressWheel) customProgressDialog.findViewById(R.id.dialog_ProgressWheel);
		ProgressWheel.setVisibility(Visibility);

		customProgressDialog.getWindow().getAttributes().gravity = Gravity.CENTER;

		customProgressDialog.setCanceledOnTouchOutside(b);
//
//		customProgressDialog.setCancelable(false);//返回键

		return customProgressDialog;

	}

	public void setTextView(int str){
		if (customProgressDialog!=null){
			textView.setText(context.getString(str));
		}
	}

}
